<?php
defined( 'JOSCOM_VERSION' ) or die( 'Direct Access to this location is not allowed.' );
  if (!($acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'all' )
  | $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'com_banners' ))) {
    //j15nc
  }
  if (defined( '_OSCOMMERCE_LOADED' )) {
    if (!DB_SHARED) {
      tep_db_connect() or die('Unable to connect to database server!');
    }
    global $category_links, $languages_id, $cPath, $cPath_array, $current_category_id;
    global $request_type, $lng, $cart, $currencies, $language, $navigation, $breadcrumb;
  } else {
    require(DIR_WS_COMPONENT . 'includes/application_top.php');
  }
  
  
//include('includes/ajax_top.php');

include('includes/classes/google_translates.php');

	$language_encoding_array = array("japanese"=>"EUC-JP",
									"chinese"=>"BIG5",
									"tchinese"=>"BIG5",
									"english"=>"ISO-8859-1",
									"espanol"=>"ISO-8859-1",
									"italian"=>"ISO-8859-1",
									"portugues"=>"ISO-8859-1",
									"german"=>"ISO-8859-1");
									
	$language_decoding_array = array("ar|en" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"zh|en" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"zh-CN|zh-TW" => "UTF-8, BIG5, EUC, EUC-JP, SJIS, ISO-8859-1, ISO-8859-15",
									"zh-TW|zh-CN" => "UTF-8, BIG5, EUC, EUC-JP, SJIS, ISO-8859-1, ISO-8859-15",
									"nl|en" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"en|ar" => "UTF-8, ISO-8859-6, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"en|zh-CN" => "UTF-8, BIG5, EUC, EUC-JP, SJIS, ISO-8859-1, ISO-8859-15",
									"en|zh-TW" => "UTF-8, BIG5, EUC, EUC-JP, SJIS, ISO-8859-1, ISO-8859-15",
									"en|nl" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"en|fr" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"en|de" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"en|el" => "UTF-8, ISO-8859-7, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"en|it" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"en|ja" => "UTF-8, EUC, EUC-JP, SJIS, BIG5, ISO-8859-1, ISO-8859-15",
									"en|ko" => "UTF-8, EUC-KR, EUC, EUC-JP, SJIS, BIG5, ISO-8859-1, ISO-8859-15",
									"en|pt" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"en|ru" => "UTF-8, ISO-8859-5, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"en|es" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"fr|en" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"fr|de" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"de|en" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"de|fr" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"el|en" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"it|en" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"ja|en" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"ko|en" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC-KR, EUC, EUC-JP, SJIS, BIG5",
									"pt|en" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"ru|en" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5",
									"es|en" => "UTF-8, ISO-8859-1, ISO-8859-15, EUC, EUC-JP, SJIS, BIG5"); 
	
if (($_GET['text'])&& ($_GET['language_pair'])){
	
	$text = urldecode($_GET['text']);
	$language_pair = $_GET['language_pair'];

	//echo $text." ".$language_pair."<br>";
	while( @ob_end_clean() );
	$g = new Google_API_translator();
	$g->setOpts(array("text" => $text, "language_pair" => $language_pair));
	$g->translate();

	if ($g->out!=''){

		if (($language_pair == "en|ja") || ($language_pair == "en|zh-TW")) {
	
			$string = $g->out;
			
			$encoding = mb_detect_encoding($string, $language_decoding_array[$language_pair]);
			$string = mb_convert_encoding($string, "UTF-8", $encoding);
			
			echo $string;
	
			//echo $g->out;
		} else {
			echo utf8_encode($g->out);
		}
	} else {
		echo "Nothing returns from Google Translate";
	}

}


include('includes/ajax_bottom.php');



?>